package com.zz.framework.core.utils.sandbox

import android.graphics.Bitmap
import android.net.Uri
import com.zz.framework.core.utils.file.sandbox.DirectoryType
import java.io.InputStream

/**
 * Copyright © 2024 zhun All rights reserved.
 * Created by Zha0Zhun on 2024/6/21 23:20.
 * @author: Zha0Zhun 1820022519@qq.com
 * @version: V1.0
 */
interface IFile {
    /**
     * 通过 ByteArray 创建文件
     * @param displayName String 新建文件的名称
     * @param content ByteArray 新建文件的内容
     * @param onSuccess Function1<Uri, Unit> 成功回调
     * @param onError Function1<Exception, Unit> 失败回调
     */
    fun newFile(displayName: String, content: ByteArray, onSuccess: (Uri) -> Unit, onError: (Exception) -> Unit)

    /**
     * 通过 InputStream  创建文件
     * @param displayName String 新建文件的名称
     * @param inputStream InputStream 新建文件的内容
     * @param onSuccess Function1<Uri, Unit> 成功回调
     * @param onError Function1<Exception, Unit> 失败回调
     */
    fun newFile(displayName: String, inputStream: InputStream, onSuccess: (Uri) -> Unit, onError: (Exception) -> Unit)

    /**
     * 通过 Uri 删除文件
     * @param uri Uri 文件Uri
     * @param onSuccess Function0<Unit> 成功回调
     * @param onError Function1<Exception, Unit> 失败回调
     */
    fun deleteFile(uri: Uri, onSuccess: () -> Unit, onError: (Exception) -> Unit)

    /**
     *  通过文件名称删除文件
     * @param displayName String 文件名称
     * @param onSuccess Function0<Unit> 成功回调
     * @param onError Function1<Exception, Unit> 失败回调
     */
    fun deleteFile(displayName: String, onSuccess: () -> Unit, onError: (Exception) -> Unit)

    /**
     * 通过文件Uri读取文件
     * @param uri Uri  文件Uri
     * @param onSuccess Function1<ByteArray, Unit> 成功回调
     * @param onError Function1<Exception, Unit> 失败回调
     */
    fun readFile(uri: Uri, onSuccess: (ByteArray) -> Unit, onError: (Exception) -> Unit)

    /**
     * 通过文件名称读取文件
     * @param displayName String 文件名称
     * @param onSuccess Function1<ByteArray, Unit> 成功回调
     * @param onError Function1<Exception, Unit> 失败回调
     */
    fun readFile(displayName: String, onSuccess: (ByteArray) -> Unit, onError: (Exception) -> Unit)

    /**
     *
     * @param displayName String
     * @param onSuccess Function1<Uri?, Unit>
     */
    fun queryFileByName(displayName: String, onSuccess: (Uri) -> Unit, onError: (Exception) -> Unit )

    /**
     *
     * @param uri Uri
     * @param newContent ByteArray
     * @param onSuccess Function0<Unit>
     * @param onError Function1<Exception, Unit>
     */
    fun updateFile(uri: Uri, newContent: ByteArray, onSuccess: () -> Unit, onError: (Exception) -> Unit)

    /**
     *
     * @param displayName String
     * @param newContent ByteArray
     * @param onSuccess Function0<Unit>
     * @param onError Function1<Exception, Unit>
     */
    fun updateFile(displayName: String, newContent: ByteArray, onSuccess: () -> Unit, onError: (Exception) -> Unit)

    /**
     *
     * @param uri Uri
     * @param newDisplayName String
     * @param onSuccess Function1<Uri, Unit>
     * @param onError Function1<Exception, Unit>
     */
    fun renameFile(uri: Uri, newDisplayName: String, onSuccess: (Uri) -> Unit, onError: (Exception) -> Unit)

    /**
     *
     * @param displayName String
     * @param newDisplayName String
     * @param onSuccess Function1<Uri, Unit>
     * @param onError Function1<Exception, Unit>
     */
    fun renameFile(displayName: String, newDisplayName: String, onSuccess: (Uri) -> Unit, onError: (Exception) -> Unit)

    /**
     * @param inputStream InputStream
     * @param displayName String
     * @param onSuccess Function1<Uri, Unit>
     * @param onError Function1<Exception, Unit>
     */
    fun writeInputStreamToAlbum(inputStream: InputStream, displayName: String, onSuccess: (Uri) -> Unit, onError: (Exception) -> Unit)

    /**
     *
     * @param displayName String
     * @param bitmap Bitmap
     * @param onSuccess Function1<Uri, Unit>
     * @param onError Function1<Exception, Unit>
     */
    fun addBitmapToAlbum(displayName: String, bitmap: Bitmap, onSuccess: (Uri) -> Unit, onError: (Exception) -> Unit)

    fun  mkdirs(displayName: String, directoryType: DirectoryType, onSuccess: (Uri) -> Unit, onError: (Exception) -> Unit)

    fun getFileName(uri:Uri):String?
}